layui.use(['form', 'layer'], function() {

    var form = layui.form
        ,layer = layui.layer;
    
    $(function () {
        form.on('submit(formDemo)', function(data) {

            //验证输入的密码是否相同
            var newPwd = $("#newPwd").val();
            var confirmNewPwd = $("#confirmNewPwd").val();
            if (newPwd != confirmNewPwd) {
                layer.msg("两次输入的密码不一致", {
                    "icon": 2,
                    "time": 2000
                });
                $("#confirmNewPwd").val("");
                return false;
            }

            var uId = $(".uId").val();
            var oldPwd = $("#oldPwd").val();
            $.ajax({
                url:"/user/updatePwd",
                type:"put",
                data:{uId:uId, oldPwd:oldPwd, newPwd:newPwd},
                success:function (result) {
                    if (result.code == 200){
                        //修改成功
                        layer.msg(result.msg);
                        setTimeout(function () {
                            //当你在iframe页面关闭自身时
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        }, 1500);
                    } else {
                        layer.msg(result.msg);
                    }
                }
            });
            return false;
        });

    })
});